﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Xk
{
    public partial class frmStudentLinqToDataSet : Form
    {
        public frmStudentLinqToDataSet()
        {
            InitializeComponent();
        }

        private dsXk.StudentDataTable CreateStudents()
        {
            SqlConnection cn = new SqlConnection(Properties.Settings.Default.XkConnectionString);
            string sql = "SELECT * FROM Student";
            SqlDataAdapter da = new SqlDataAdapter(sql, cn);
            dsXk.StudentDataTable t = new dsXk.StudentDataTable();
            da.Fill(t);
            return t;
        }

        private void getStudent()
        {
            listBox1.Items.Clear();
            var results = from c in CreateStudents()
                          where c.StuName.Contains(txtStuName.Text)
                          select c;
            foreach (var r in results)
            {
                listBox1.Items.Add("姓名：" + r.StuName + "性别：" + r.Sex);
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            getStudent();
        }
    }
}
